from Info import Info
import MySQLdb
data_info = {
    'access_token': '67e21abe38e6c74af2a1dc3788eda6e2',
    'org': 'OpenHarmony',
    'owner': 'OpenHarmony',
    'repo': 'ace_ace_engine',
    'username': 'laokz'
}
info = Info(data_info)
info = info.get_orgs_members_info()
# print(len(info.get_orgs_members_info()))
# print(len(info.get_orgs_repos_info()))
# print(len(info.get_repos_collaborators_info()))
# print(len(info.get_users_followers_info()))
# print(info.get_orgs_info())
# print(info.get_users_info())
# print(len(info.get_repos_commits_info()))
db = MySQLdb.connect(host='127.0.0.1', port=3306, user='FL-Rover', passwd='12345678', db='test', charset='utf8')
cursor = db.cursor()
create_sql = """CREATE TABLE IF NOT EXISTS USER (
        ID INT,
        LOGIN CHAR(20),
        NAME CHAR(20),
        AVATAR_URL CHAR(100)
        )"""
insert_sql = 'INSERT INTO USER(ID, LOGIN, NAME, AVATAR_URL) VALUES(%s, \'%s\',\'%s\', \'%s\')'
select_sql = 'SELECT * FROM USER WHERE ID=%s'
update_sql = 'UPDATE USER SET LOGIN=\'%s\', NAME=\'%s\', AVATAR_URL=\'%s\' WHERE ID=%s'
cursor.execute(create_sql)
for member in info:
    if cursor.execute(select_sql % member['id']):
        cursor.execute(update_sql % (member['login'], member['name'], member['avatar_url'], member['id']))
    else:
        cursor.execute(insert_sql % (member['id'], member['login'], member['name'], member['avatar_url']))
        db.commit()
db.close()
